﻿/********************************************************************************************
 * 文件名称:	Nation.cs
 * 设计人员:	yanxianghui@gmail.com
 * 设计时间:	2009-07-26
 * 功能描述:	国家字典表
 *		
 *		
 * 注意事项:	
 *
 * 版权所有:	Copyright (c) 2007, Fujian SIRC
 *
 * 修改记录: 	修改时间		人员		修改备注
 *				----------		------		-------------------------------------------------
 *
 ********************************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using Shanfree.SharpMovie.Model;
using Shanfree.SharpMovie.IDAL;
using Shanfree.SharpMovie.DALFactory;

namespace Shanfree.SharpMovie.BLL
{
    /// <summary>
    /// 国家字典表
    /// </summary>
    public class Nation
    {
        private static readonly INation dal = DataAccess.CreateNation();

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IList<NationInfo> GetList()
        {
            return dal.GetList();
        }
        
        /// <summary>
        /// 根据列表
        /// </summary>
        /// <param name="movieID">电影主键</param>
        /// <returns></returns>
        public IList<NationInfo> GetListByMovieID(string movieID)
        {
            if (string.IsNullOrEmpty(movieID))
            {
                throw new ArgumentNullException("movieID");
            }
            return dal.GetListByMovieID(movieID);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="menuID">ID</param>
        /// <returns></returns>
        public NationInfo GetByID(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }
            return dal.GetByID(id);
        }
        /// <summary>
        /// 根据英文名称获取国家实体
        /// </summary>
        /// <param name="englishName">国家的英文名称</param>
        /// <returns></returns>
        public NationInfo GetByValue(string englishName)
        {
            if (string.IsNullOrEmpty(englishName))
            {
                throw new ArgumentNullException("englishName");
            }
            return dal.GetByValue(englishName);
        }

        public string Add(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("国家名称不能为空。");
            }
            NationInfo nInfo = new NationInfo();
            nInfo.Name = name;
            return dal.Add(nInfo);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id">主键</param>
        public void Delete(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }
            NationInfo nInfo = new NationInfo();
            nInfo.ID = id;
            dal.Update(nInfo);
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="id">记录主键</param>
        /// <param name="IMDB_ID">IMDB编号</param>
        /// <param name="OriginalName">影片名称</param>
        /// <param name="EnglishName">英文名称</param>
        /// <param name="ChineseName">中文名称</param>
        /// <param name="HongkongName">台港澳名称</param>
        /// <param name="PostLink">海报链接</param>
        /// <param name="ProduceYear">上映年份</param>
        /// <param name="Director">导演</param>
        /// <param name="LeadingRule">主演</param>
        /// <param name="Introduce">简介</param>
        /// <param name="Awards">获得奖项</param>
        public void Update(string id, string name)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("主键不能为空。");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("国家名称不能为空。");
            }
            NationInfo nInfo = new NationInfo();
            nInfo.ID = id;
            nInfo.Name = name;
            dal.Update(nInfo);
        }

        /// <summary>
        /// 将国家文本转化为列表
        /// </summary>
        /// <param name="nameList">国家字符串：USA,UK</param>
        /// <returns></returns>
        public IList<NationInfo> GetByNameList(string nameList)
        {
            IList<NationInfo> nList = new List<NationInfo>();
            bool hasOther = false;
            string[] nationArray = nameList.Split(',');
            for (int i = 0; i < nationArray.Length; i++)
            {
                string english = nationArray[i].Trim();
                NationInfo nInfo = dal.GetByValue(english);
                if (nInfo.EnglishName == "Other" && hasOther == true)
                {
                    continue;
                }
                else if (nInfo.EnglishName == "Other" && hasOther == false)
                {
                    hasOther = true;
                }
                nList.Add(nInfo);
            }
            return nList;
        }
    }
}
